#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
typedef long long LL;
LL f[N] , a[N];
int main()
{
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++)
  {
    cin >> a[i];
    cout << f[i - 1] << " "; 
    f[i] = f[i - 1] + a[i];
  }
  cout << endl;
  LL sum = 0;
  for(int i = 1; i <= n; i++)
  {
    sum += a[i] * (f[n] - f[i]);
  }
  cout << sum << endl;
  return 0;
}
